{{define "demo/media/edit"}}
    {{template "layout_form" .}}
{{end}}

{{define "js_common"}}
    {{block "dragula" .}}{{end}}
    {{block "uploader" .}}{{end}}
{{end}}

{{define "content"}}
<form class="form-horizontal m" id="form-edit">
    <input type="hidden" name="id" value="{{.info.Id}}">
    <div class="form-group">
        <label class="col-sm-2 control-label is-required">单图片上传：</label>
        <div class="col-sm-8">
            <input type="hidden" name="img" value="" id="img" required>
            {{ $upload_img_data := printf "data:%s" .info.Img}}
            {{ $upload_img := call .func.dataSet "ctx" . (call .func.makeMap $upload_img_data "name:img_upload" "cat:demo" "link:1" "tips:格式为jpg,jpeg,png,gif；大小不能超过10M") }}
            {{template "upload_img" $upload_img}}
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label is-required">多图片图片上传：</label>
        <div class="col-sm-8">
            <input type="hidden" name="imgs" value="" id="imgs" required>
            {{ $upload_imgs_data := printf "data:%s" .info.Imgs}}
            {{ $upload_imgs := call .func.dataSet "ctx" . (call .func.makeMap $upload_imgs_data "name:imgs_upload" "multi:5" "cat:demo" "link:1" "tips:格式为jpg,jpeg,png,gif；大小不能超过10M；最多上传5张；可拖动排序")}}
            {{template "upload_img" $upload_imgs}}
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label is-required">裁剪上传：</label>
        <div class="col-sm-8">
            <input type="hidden" name="crop" value="" id="crop" required>
            {{ $upload_crop_data := printf "data:%s" .info.Crop}}
            {{ $upload_crop := call .func.dataSet "ctx" . (call .func.makeMap $upload_crop_data "name:crop_upload" "multi:2" "crop:1" "cat:demo" "link:1" "tips:格式为jpg,jpeg,png,gif；大小不能超过10M；最多上传5张；可拖动排序") }}
            {{template "upload_img" $upload_crop}}
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label is-required">上传视频：</label>
        <div class="col-sm-8">
            <input type="hidden" name="video" value="" id="video" required>
            {{ $upload_video_data := printf "data:%s" .info.Video }}
            {{ $upload_video := call .func.dataSet "ctx" . (call .func.makeMap $upload_video_data "name:video_upload" "cat:demo" "tips:格式为mp4；大小不能超过100M") }}
            {{template "upload_video" $upload_video}}
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-2 control-label is-required">单文件：</label>
        <div class="col-sm-8">
            <input type="hidden" name="file" value="" id="file" required>
            {{ $upload_file_data := printf "data:%s" .info.File }}
            {{ $upload_file := call .func.dataSet "ctx" . (call .func.makeMap $upload_file_data "name:file_upload" "cat:demo" "link:1" "exts:txt|rar|doc|png" "tips:格式为txt|rar|doc|png；大小不能超过100M") }}
            {{template "upload_file" $upload_file}}
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-2 control-label is-required">多文件文件：</label>
        <div class="col-sm-8">
            <input type="hidden" name="files" value="" id="files" required>
            {{ $upload_files_data := printf "data:%s" .info.Files }}
            {{ $upload_files := call .func.dataSet "ctx" . (call .func.makeMap $upload_files_data "name:files_upload" "cat:demo" "link:1" "multi:3" "exts:txt|rar|doc|png" "tips:格式为txt|rar|doc|png；大小不能超过100M") }}
            {{template "upload_file" $upload_files}}
        </div>
    </div>
    <div class="row m-t-md">
        <div class="col-sm-offset-5 col-sm-10">
            <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>
            <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
        </div>
    </div>
</form>
{{end}}
{{define "script"}}
    <script>
        function submitHandler() {
            var img = '';
            var imgs = [];
            var crop = [];
            var file = [];
            var files = [];

            if($("input[name='img_upload[]']").length>0){
                $("input[name='img_upload[]']").each(function () {
                    var imgval = $(this).val();
                    if(imgval){
                        img = imgval;
                    }
                })
            }
            $("#img").val(img);

            if($("input[name='imgs_upload[]']").length>0){
                $("input[name='imgs_upload[]']").each(function () {
                    var imgval = $(this).val();
                    if(imgval){
                        imgs.push(imgval)
                    }
                })
            }
            $("#imgs").val(imgs.join(','));

            if($("input[name='crop_upload[]']").length>0){
                $("input[name='crop_upload[]']").each(function () {
                    var imgval = $(this).val();
                    if(imgval){
                        crop.push(imgval)
                    }
                })
            }
            $("#crop").val(crop.join(','));

            $("#video").val($("#videourl_video_upload").val());

            if($("input[name='file_upload[]']").length>0){
                $("input[name='file_upload[]']").each(function () {
                    var imgval = $(this).val();
                    if(imgval){
                        file = imgval
                    }
                })
            }
            $("#file").val(file);

            if($("input[name='files_upload[]']").length>0){
                $("input[name='files_upload[]']").each(function () {
                    var imgval = $(this).val();
                    if(imgval){
                        files.push(imgval)
                    }
                })
            }
            $("#files").val(files.join(','));

            if ($.validate.form("",{ignore:""})) {
                $.operate.saveTab(window.b5go.oesUrl, $('#form-edit').serialize());
            }
        }
    </script>
{{end}}
